package grobit.tracker

import java.nio.ByteBuffer

class PeerId {
    static byte[] id = new byte[20]

    static {
        // GROBIT + version + time + random
        ByteBuffer buf = ByteBuffer.wrap(id)
        'GROBIT'.getBytes().each { buf.put(it) }
        buf.put(0 as byte) // Ver 0.1
        buf.put(1 as byte)
        buf.putLong(System.currentTimeMillis())
        Random random = new Random()
        buf.putInt(random.nextInt())
    }

    static byte[] get() {
        byte[] data = new byte[20]
        System.arraycopy(id, 0, data, 0, id.length)
        return data
    }

    private PeerId() { }
}
